package com.yanqu.road.dataHelper.crossServer;

import com.yanqu.road.dataHelper.manager.ServerMgr;
import com.yanqu.road.entity.servercenter.DbInfo;
import java.sql.*;
public class CrossServer extends Base {


    public CrossServer(long crossServerId){
        try {
            DbInfo dbInfo = ServerMgr.getDbCrossInfoMap().get(crossServerId);
            getLogger().info("crossConnect : {}, {}, {}", "jdbc:mysql://" + dbInfo.getIp() + ":" + dbInfo.getPort() + "/" + dbInfo.getDbName()+"?useUnicode=true&character_set_server=utf8mb4&useSSL=false", dbInfo.getUserName(), dbInfo.getPassword());
            connection =  DriverManager.getConnection("jdbc:mysql://" + dbInfo.getIp() + ":" + dbInfo.getPort() + "/" + dbInfo.getDbName()+"?useUnicode=true&character_set_server=utf8mb4&useSSL=false", dbInfo.getUserName(), dbInfo.getPassword());
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println("连接失败！");
        }
    }

    public void test(long a,String b){
        System.out.println(a);
        System.out.println(b);
        try {
            ResultSet rs = null;
            CallableStatement call = null;
            call = connection.prepareCall("select * from t_u_user limit 1");
            rs = call.executeQuery();
            while (rs.next()) {
                long userId = rs.getLong("userId");
                System.out.println("userId : " + userId);
            }
        } catch (SQLException e) {
            logger.error("异常错误",e);
        }
    }
}
